CLN: Refactor open into context manager in io tests
- [ ] closes #xxxx
- [ ] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

Building on #21105 by @WillAyd, I cleaned up some more `open` statements.