Logging to a file after every 1000 lines