"And Moab said to the elders of Midian" (Numbers 22:4). And do you not find that the Midianites would wage war with the Moabites? As it is said, "who smote Midian in the field of Moab" (Genesis 36:35). And the hatred between them existed from of old. A parable of two dogs who were hostile to one another: a wolf came upon one of them. His companion said: If I do not help him, today it kills this one, and tomorrow it will come upon me. Therefore Moab joined together with Midian.
Why Moab and Midian United Against Israel in Balak
Midrash Tanchuma Buber, Balak 4:2
ויאמר מואב אל זקני מדין. והלא אתה מוצא שמדינים נלחמין עם המואבים, שנאמר המכה את מדין בשדה מואב (בראשית לו לה), והשנאה ביניהם מעולם, משל [לשני] כלבים שהיו צהובין זה לזה, בא זאב על אחד מהם, אמר חבירו אם איני עוזרו, היום הורג את זה, למחר יבא עלי, לפיכך נתחברו מואב עם מדין.