I looked at this again and got suspicious becuase I noticed that the number of pen commands increased from 4 to 6, whereas I only expected it to be 5 (4+1) in the outputImpliedClosingLine=True case.
Turns out we are adding an extra duplicate lineTo right after moveTo, which I think is not correct.