L298N Motor Controllers act different connected and disconnected from computer

Hello,
I am testing the four wheel drive for a robot I am building so I made a simple code that turns the motors forwards and backwards just to test that they are connected and working. Unfortunately....the motors only go forward as if they get to the part of the code they go forward and decide to not reverse direction. This only happens however, when I disconnect the arduino mega from my computer. If I run the code with it plugged into my laptop, the motors actually change directions, bet the second I unplug it from USB it only goes forwards. I have both motors i'm using connected to a variable bench power supply. My code is as follows:

#define RM_FWD 2
#define RM_BWD 3
#define RM_ENA 9
void setup() {
// put your setup code here, to run once:
pinMode(solenoid, OUTPUT);
pinMode(RM_FWD, OUTPUT);
pinMode(RM_BWD, OUTPUT);
pinMode(RM_ENA, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
analogWrite(RM_ENA, 500);
digitalWrite(RM_FWD, HIGH);
digitalWrite(RM_BWD, LOW);
delay(5000);
digitalWrite(RM_FWD, LOW);
digitalWrite(RM_BWD, HIGH);
delay(5000);
}

Any help would be appreciated as I have no clue what could be causing it to behave differently when connected through USB......

Please post a pic of a hand drawn wiring diagram with pins and parts clearly labeled.

Also, show how the Arduino is powered when it is not connected via USB.

I can only guess but it sounds like a ground loop problem. Your laptop is floating from ground, your computer is grounded. Check this out you should find your problem. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

analogWrite(RM_ENA, 500);

Which Arduino are you writing this for?
Leo..