While some unneeded units in Iraq have been sent on to Afghanistan, this has not happened a lot. The main reason is transportation. The troops are flown in, but the equipment goes by ship, rail (from the Pakistani port of Karachi) and truck (into Afghanistan, which has no railroads). That can take a month or more. In the meantime, the troops are sitting around with not much to do.
Thousands of troops have been sent straight from Iraq to Afghanistan, but these were usually tech specialists (intelligence, maintenance, administrative, logistics) who simply join units in Afghanistan that need them, and get to work. But for combat, or transportation, troops, they can't do their work without a lot of gear. Some of that stuff can be flown in, but that's a lot more expensive, and often there are simply not enough aircraft available.
So in most cases, it makes more sense to send troops home, along with their equipment (unless the Iraqis have bought it, which they have done with a lot of used American vehicles and heavy equipment), and send fresh units to Afghanistan. Which brings up another problem. When you send a unit from Iraq to Afghanistan, it will be leaving Afghanistan early. That's because units do "overseas" tours of 3-12 months, and as soon as they have been in Iraq or Afghanistan (or any number of other places) for the length of their tour, they go home. To do otherwise is really, really bad for morale.