If you suspect you have an electrical problem such as an overload or noise on the circuit caused by the motors, you can investigate by disconnecting the wires to the motors (leave the sketch the same) and see whether the problems stop. That would give you an idea whether it was genuinely an electrical problem, or some other logical fault in your sketch or hardware circuit.