added writing output to file