Implement write_to_disk and test