Hi,
> Any ideas as to why this happens?

No, not really I'm afraid and I'm not in a position where I can wire it up and test here....
Since both mine and Alains code experience the same issue it feels like a hardware problem or a configuration problem but as far as I can see you've got CMCON, ANSEL and MCLR covered so I don't know.

Or it might be something completely obvious - which we're all missing at the moment.

Couple of, perhaps completely unrelated, questions:
* Does it do the same thing for both "sides" or only one? (If only one, which?)
* Do you program the chip in circuit and is the device programmer still connected to the target when this happens?
* Can you post a schematic of how you have it wired?

/Henrik.