writing to output file working