Add function to write the output in a file