Balancing is done purely by the "Score" at the end of the game.
So if you go 30-5 and therefore have 3000 points (let's assume a TDM with no assists) then since the max score is 7500, it puts you with all the players who got really **** scores to "balance" our the average scores of all of the remaining players. New players are assigned to teams randomly.
Next time you and one other guy on your team pretty much take the game (you = 27-5 : he=28-10) and the other 4 guys on your team make up the remaining 10 kills, you'll notice that virtually NEVER will you and that guy be on the same team again. UNLESS you are partied together. IW wont seperate partied guys for obvious reasons.