Adding output file writing