DC Motor & L293D

Hi,
Your problem is probably the Arduino resetting itself due to insufficient or noisey power.

What are you using for power ?

Is there any decoupling on the power between the motors and the Arduino ?

Are you putting the same voltage into the 293 through VSS and VS ?

Duane B