Added f.close() to close files wherever opened

A good developer closes every file opened in the program..