Exactly so and I think that may be a partial cause of the problem. In source mode those pins will only drive the Opto at about 7mA, it really needs 12 or more, and they will be susceptible to ground noise. In sink mode they can easily manage 15mA. I'm guessing you're driving the DIR line the same way and driving it high, which would also explain the occasional reversal.

As a first step, excuse the pun, I'd change this to use an active low approach.