What is causing an intermittent side to side wobble of the rear cogs?
Check:


Freehub body: no play radially? laterally? Try to reproduce it when lightly apply the brake (with barrel adjuster) and hand-pedal while the bike on stand. does it still wobble?
Cassette spacing: remove the cassette and see if there is any irregularities in the spacer.