Output to file, optimisation