Implement writing to a file.