Could be a timing issue - the first time the script run the profile has not been established. The second time it runs the profile has been established and the script works as expected.

If this is the case, ensure that you are running the script synchronously. This will wait for the user environment to establish before running the logon script, if it is a legacy logon script.

For more information search the board / web for RunLogonScriptSync