I remember of few strange behaviour with this specific PWM. As far as i remind, it trick the TRIS setting and sometimes it set the i/o to input at the end.

Try to use LOW and HIGH after PWM instead of using Io=1 or Io=0