I think it would be good o add the file closing statements in a try's finally block so you make sure the files get closed even if an exception is being raised while executing the above for loop.