Could you either way elaborate on that calculation you're making
If the LED in the opto drops 1.25V then there must be 5 - 1.2 = 3.8V dropped across the resistor.
In order to have 30mA flowing through a resistor with 3.8V across it the resistor value must be 3.8 / 0.03 = 126.666666 ohms
Which is a value you can't buy so the closest would be 125R.
As to the original problem using analogue write automatically sets the pin to be an output where as the digital write requires it to be set separately. I know the code you posted does this but is there any chance this got missed originally?