Changing file operations to use `with`

* Open and Close is always flaky. We tend to forget. With is a better
  way to do these things