added function to write the metadata to a file.