now writing output to file instead of stdout