It's an attempt to prevent check washing. Probably not super effective these days but it does make it slightly harder.
When a check washer gets ahold of a check, they use a chemical like acetone (most checks are now designed to react to acetone as a countermeasure) to remove the existing ink and to change the payee, the amount, or both. Then they re-write the check and deposit it. Even if the criminal successfully removes the ink, they can't remove the indentations the pen made in writing out the check (or at least smoothing out the area adds extra complexity to the process).
In the days when checks were deposited by handing a physical piece of paper to a physical bank teller, having the line made it a bit easier for that teller to notice that the check had been washed if the new amount extended over the erased line (as would normally be the case if a leading digit was added). Not foolproof by any means but a reasonable security layer particularly where it makes the check feel "off" enough that a busy teller pauses to give it a second look. In today's world where only photographs are exchanged in the vast majority of cases, it's much less useful.