The read_line function appends to the given buffer which is never cleared. This leads to lines being duplicated.