I agree this should be a cron task instead. I don’t see why everyone wants to use HA to do things that can easily (and should) be done by other means.
Anyways, my guess is that it is a user or permission issue. If you logged in a tested the script as MyUser and Home-Assistant runs under hass then you are likely to run into problems.