Generally encoders fail completely, not intermittently.

Have you checked all the wiring is OK?
A broken wire (or one making intermittent connection) would give those kinds of symptoms.

RouterCNC's suggestion of connecting an oscilloscope would give a far better diagnosis.