Make fileutil helpers use reader/writers so they can be used in more places

- Closed some more file descriptors that weren't being closed [fixes #60300444]