That helped. There was something I had forgotten that you have figured out... adding spaces (or some other character) to fill the line.
So the problem is that on two of those lines (the two that are shorter than the maximum length) the first character in the line is missing, right? I don't see the problem straight away, but at least you've narrowed the problem to a specific issue.
One question I have is for lines that are more than one character shorter than the maximum, doesn't your code only add a single space? I would think you should add a loop for adding the spaces to the end if it is shorter than the width.