When you run the code in your other script is it executing in a manual mode or as a logon script during logon?

If it is during logon then you have some OS level thing happening causing the different behavior. You didn't specify what OS you were testing with in any previous post that I saw.
Home page: http://www.kixhelp.com/hb/