MAINT: #2312, Make all tofile failures raise IOError.

Fix two that were raising ValueError instead.
Make some style cleanups.

Closes #2312.
DOC: Document tofile exception changes in 1.9.0 release notes.
Merge pull request #4333 from charris/fix-gh-2312

Fix gh 2312