$env:USERPROFILE
is not going to resolve as you expect because the action will be running as LocalSystem, not as the account of a logged-on user.
You’ll need to either change the logic to loop through all of the user profiles instead of relying on $env, or use action overrides to execute the script in the context of a logged-on user instead of LocalSystem. I have some notes on the action overrides settings at Tip - Action Override User settings that may be useful.
(Edit: fixed link)