Remove all "U" mode for files

It is now deprecated
Remove redundant code working around "U" file mode issues
Explcitly close some files

This prevents resource warnings