Added function for output to file