added simpler write_to_txt function