If the only trouble is while he's in line, how about talking with the teacher about giving him something to carry while he's in line? For example, if they're going to lunch, he could carry the basket full of brought lunches. Or, if they're going to the library, he could carry the basket full of books. It would take 2 hands, and he wouldn't be able to bother anyone. If the class doesn't currently use a basket for books, maybe the teacher would be willing to adopt the practice in order to help your son. If not, maybe she would work with you to create some kind of something that "needs" to be taken with the class whenever they walk in the hall. Some teachers have a class notebook that travels with the students when they go to other parts of the school (so the art teacher, pe teacher, or whomever can write notes to the classroom teacher about how well the student performed or behaved while they were in that class). Maybe something like that? Maybe you could offer to actually create the thing (whatever it is) in order to save the teacher from having an extra job to do. If a system like this could be put into place, your son would think he is doing a good and responsible deed, which would build his self-esteem and NOT make the problem worse. He'd never need to know it was designed to keep him out of "trouble."
Kids at this age are often impulsive, so there's hope he will grow out of the behavior. I think it would be wise to also continue working on "keeping hands to yourself" and teaching him alternatives to hitting. What else can you do if someone makes you mad, or gets in your way, or takes your turn, or whatever. Little guys sometimes can't think their way through things unless we specifically give them the tools. Role playing at home is a great way to practice, with you being the kid who does something to provoke your son. Or have him practice with his little brother, in role play or for real!