prefix writer: simplify, preserve trailing \n

not sure if i'm missing any of the subtleties of the previous code. noticed it was lopping off trailing linebreaks and munging things together awkwardly some times. updated the test to preserve trailing linebreak and ended up rewriting the algorithm.

this is what I was seeing before:

http://cl.ly/image/0V2M0y233V3h