Useful side effects for sure, but even if you took away the direct non-financial costs of the military (non-zero chance of nuclear armageddon...), I think there are things we as a species could work on which would produce the same kind of competitive, focused effort. The "space race" accomplished a lot, and consumer IT tech (say, mobile phones) has progressed even faster than military tech (outside maybe an existential war like WW2).
I don't disagree with your wider point that their are other useful motivators out there but it's worth noting that the space race was militarily motivated. Sputnik flying overhead effectively showed the soviets had/would have the ability to drop bombs anywhere in the world. Even the space shuttle was influenced in design by militaristic influence.