Most likely you are exceeding the optocoupler's dv/dt rating. That could be cured with a snubber circuit.
Having said that, I remember reading many times advice from optocoupler's manufacturers that the optocouplers are only designed to trigger triacs..... and not to drive a load directly, therefore you should use a triac as in your second image.
For instance, read the note on the middle of page 6 in the following datasheet:
https://www.fairchildsemi.com/ds/MO/MOC3023M.pdf