Why does my Arduino not work correctly when I disconnect the USB?

Yep, and the drawing you provided allowed us to nail the issue quickly. Funny how that works! The 5V from Uno to Relay stood right out on the sketch, and the relay image showing that they were 5V relays also gave it away..
The prize goes to the author of post 18, he got there first.

Sometimes we can't see the forest for the trees! Thanks for the help. I think we have solved the problem, maybe. It's been going through the program and show for almost an hour and half so far. I'll let it run the rest of the evening and see how we turn out tomorrow when I re-start it. fingers crossed...

Thanks for your help on this.

I see so many of these and I have changed my advice to NEVER use the board as a power supply. Sure it will work for a temp or humidity sensor, but just get in the habit so when you add a big draw 2 yrs later it will still work instead of failing if the board was the PSU.

I try not to be "dogmatic" - for example, onboard regulation works just fine for a few LEDs; my threshold tends to be, if you've got offboard stuff, use an offboard supply. Although even then, it's all simply math. Add up your loads, consider your source, then be conservative.

To me, it's better to teach a bit of 'electron counting' rather than to enforce dogma. Post #18 is a good example.

I understand your point and is why I said somewhere else today that the rules for experienced users are indeed like post #18, but for beginners it is better (in my opinion) to just do the external PSU and concentrate on the meat of the project.