(Problem is exhibites on windows Server 2003 with Python 2.4. Did not try *nix platforms yet.)
If original password file does not contain empty line at the bottom (to be technical, if the last line in the file does not contain '\n' at the end of it), new user + password entries are added to the same last line. This, effectively, makes last, and all new users inaccessible.
I suggest to switch to another way of parsing / changing / adding users to password files. Maybe do something like:
file = open(filename,'rw') # this way we lock the file
lines = file.read.splitlines()
# this, as opposed to readlines() parses \r\n properly on windows
# work with the list object
file.write('\n'.join(lines))
file.close()
That approach is may be a problem on large user lists, but the intricacies of carriage returns and other glitches go away.
In the mean time, a quick solution to the problem