We eat food for getting energy to our body parts, and we excrete the wastes through urine, feces, and perspiration.
Why has nature combined the urinary tract with the genital system (urogenital system) in humans?
Developmentally, the urinary and genital systems (typically you will hear them referred to as "urogenital system") are derived from the same embryonic tissue, the intermediate mesoderm. The embryonic kidneys are drained by the mesonephric duct in both females and males. This embryonic tissue also gives rise to the ovaries and testes. The mesonephric duct degenerates in females, and becomes the ductus deferens in males. A second tube, the paramesonephric duct develops in both, but degenerates in males. The female paramesonephric duct becomes the uterine (Fallopian) tube.
Embryonically, the ureter, which drains the adult kidney is connected to the mesonephric duct. This connection is maintained in males, so that both urine and semen share a tube (urethra) for some of their exit pathway. In females, the paramesonephric duct and urethra are separate, so there are two openings.
In males, sphincter muscles and autonomic control prevent the simultaneous expulsion of urine and semen.
This system has worked acceptably well in mammals for at least about 200 million years (and in humans for the last 4 million or so), so I think it's not correct to call it a mistake. It's not how you would consciously design such a system, but evolution doesn't have a conscious designer.
Here are some slides that cover the embryology of the human urogenital system.
I would just modify the excellent previous by pointing out that the embryology describes a local maxima of fitness whose barrier to change is higher than any selective pressure. The re-use of the "logic" of the intermediate mesoderm was either initially a bifurcation from one or the other, or, was of enough selective advantage to have the two developmental processes and the resultant physical systems folded together.
kmm gives what is likely the best possible answer, as it is argued from causality rather than teleology. As my ninth grade biology teacher used to say, "there is no 'why' in biology, only 'how'".
On the other hand, it is fun to speculate! Here's my two cents in the form of a Bad ad hoc Hypothesis:
Holes going into the body are an expensive and risky prospect at best for any animal. In order to maintain homeostasis they need to keep any holes constantly supplied with fresh mucus and a ton of antibodies. Total orifice count tends to be kept to a highly conserved minimum along evolutionary lineages. Thus, the reason why urinary and genital systems are merged along a single urogential tract is so that they can both efficiently share the same hole. As evidence for this view, consider the reptile: they manage to use their holes even more efficiently than we do, mating and excreting both liquid and solid waste out of their single cloaca.