Arduino code only runs properly when powered by USB to laptop

Is there anything in your code (which you have not posted) that relies on USB communication?

Is it possible the USB cable is providing a GND connection to something?

...R