Changed from using an array for output to printing to a file handle reference