Pico W online on Blynk when I run the script via Thonny. When connected to another power source it connects to the WIFI but not to Blynk

I am using a pico w to get sensor readings from a soil moisture sensor and post them to the Blynk cloud.
When I run the script via Thonny it works flawlessly. If I just plug the pico w into the USB without running the script via Thonny, the pico w will connect to the WIFI (can be seen on the router page) but it won’t connect to Blynk (shows as offline in my dashboard).
The code file is correctly named main.py and is on the pico board itself.
Does anyone have any idea what the issue could be?

Below is a link to the project with the code:

• Raspberry Pi Pico W
• Blynk Library version 1.0.0