Revert "Simplify file writing."

This reverts commit 213afaea2838f2add5cd0dffb7dfc022dd9a804f.