If you're after a "best" implementation for you and not just wanting to choose solution A or B, a couple of other alternatives are tie::file or even create and maintain an array or hash and only write it (atomically) at end of program.
the hardest line to type correctly is: stty erase ^H