Moved some things around. Using an array to output to STDIN and to a file