Use with statement for file read/write

Since this utility now requires python 2.6 we may as well use a with
statement for file read/writes because it looks neater.