Add a final eol character when writing files

if the file being overwritten has one. This makes things more friendly
for vim users.