Summary: The puts call appends a newline. With multiple threads, this can be done out of order such that another thread puts something before we finish appending the newline. Add a flockfile and funlockfile to ensure that the whole string is printed before another string can appear.