Low Pass Filter For Square Wave Through An Optoisolator
Frankly, I suspect you have drive problems. I'd suggest monitoring the voltage across R2 as a measure of the current through the LED. If it's not perfectly clean (and I suspect it's not) that's your problem. I'd guess that your low phase has a major spike about a millisecond before nominal transition to low, and the high phase of the drive signal shows a major drop about 5 msec in, down to about a volt or less with a rather low rate of recovery.

If the drive signal is clean, try a new optocoupler. Every once in a while devices do very strange things.