When the file is run from the command line as root it works fine
I think this is the problem. I think adduser requires you to be root in order to have the right permission on the passwd file. I get the same error if I try adduser as a normal user on the command line.
Cheers,
Mathew