Added write_to_txt function