Write file-saving mechanism. Create main function.