Updated program to output to a txt file