If the assignment is online, there's absolutely no need for the teacher or grader to know the name or ID of the student at all. If its offline, there can be an ID assigned which can change randomly.
In some exams I've sat for, they used IDs to avoid people cheating or playing favorites.