implement writing to a file