Fixing USB problem in PIC18f
I had the same issue.

The cause was the tolerance and stability of the chosen oscillator.
I had chosen a ceramic resonator and this was not stable enough for operating the USB. Sometimes I got Unknown device. I replaced my clock source by a crystal with the right stability and tolerance and everything worked perfectly.

What kind of clock source do you use? what is its tolerance? Do you have any mean of measuring the clock of your system?(without probing the source directly, which could change its frequency)