Could we know if we have check the box" run scripts by using the logged on user credentials"?
If we we do not choose, it will use the system account to run the process like the situation you described. You said that you have run the script manually and it works fine, we use the user account when we run it manually, so we may need to check this place to see whether we have checked it or not?
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.