CDI can work intermittently. I've seen bikes start and idle fine and also rev out clean, but when put under a load fall flat on their faces.
Of all the things I would swap, CDI would be first.
Bad wiring harnesses also cause a lot of issues and since it's hard to see potential broken wires, you pretty much have to swap the whole thing out.
BansheeHQ has a wiring harness sponsor for that.