Could be a number of reasons.
But first the error itself is pretty clear, whatever you’re trying to do is denied due to access restrictions.
So if it works when running as a scheduled task and manually on the machine then you have a starting point.
E.g. if it works for one account, what is the difference to the other account.
Does the Get-ChildItem command access a resource that need admin privileges?
Do you run the script as admin when it works, does it work without it and so forth.
What does the scheduled task run as?
Another thing to look out for is kerberos double hop issue.
If you just google it you’ll find a number of articles about it.
But before checking if it’s a double hop issue start with checking under which circumstances it work.
E.g. with or with admin, account differences etc.