hw-2: added write to file and print to stdout