Fixed declaration bug
Added write_to_file function.