What I find is that when a horse does that it’s either because the horse used to race or is bored with what they are doing. To fix this I do a lot of circle work and halting work.
With the horses that I have dealt with having a horse like that is easy to fix, what I did was run my horse more. He or she most likely wants to race. When he or she is Exercised is more, its likely to have a calmer attitude around other horses