Writing a dictionary to a file