Refactor file io to utils

In preparation for adding the --extra-context CLI option