Replace file open/close with `with` statement.

Replace file open/close with `with` statement. `With` statement was introduced in python 2.5, and since has been the suggested method for opening and closing files. See PEP 343: http://legacy.python.org/dev/peps/pep-0343/