Use with statement to close file handle

The with statement is supported as of Python 2.6+ so this seems a safer way of expressing the same thing.