Factor out line prefixing writer, add tests
Refactors