Trying a version which updates the file and writes the string in one pass