added function for writing key-value pairs to file