The USB ports changing is a sign that the Arduino is disconnecting and reconnecting. Overloading the USB port (or the Arduino power supply) may cause this or it could be a bad USB cable, try a different cable. Just because it worked before doesn't mean it will work now. I don't think it is likely to be your code. But if you think it is the code post the code. Your other code worked fine on my Linux system. DO NOT POWER MOTORS FROM THE ARDUINO POWER SUPPLY.