Extract file writing logic from Template.
Merge remote-tracking branch 'origin/pr/115'