Changing file operations to use `with` instead of `open` and `close`

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