Teachers need to know where their students are, and what they're doing in class time. Send two kids to the toilet together, and they'll take the long way, getting distracted on the way, missing class time. As a high school teacher, I only let one student out of the room at a time. Writing out lines can also mean re-writing classroom expectations etc, as a reminder of the processes used, or behaviours expected in class. Until you know the full story, you don't know whether the teacher was justified or not.