Programmatically creating users attach profiles to correct uid on localhost but uid 1 on production
Sounds like somewhere in the first few lines of code your $account variable is getting switched to the user 1 or perhaps the currently logged in user. Perhaps trying to change the "$account" variable name to something definitely unique to see if that fixes the problem.