the reason is because of how you call fwrite. it takes 3 arguments, the last is optional, which specifies the length of the string you are writing to file.
what you should have is
fwrite($fh, $name . $password);
that will put the two values right next to eachother, if you want a space between them use
fwrite($fh, $name . ' ' . $password);