On Earth, there are several examples of similar things that evolved in two completely separate ways. A good example is how bird intelligence evolved independently of mammalian intelligence, though both can achieve similar things. In the same way, it looks like caffeine actually evolved twice on the planet, once in tea and once in coffee. This discovery came from the release of the coffee genome. Scientists found that coffee uses a completely different set of genes than tea does to bring about the same awesome buzz.
Coffee plants cover some 110-billion square meters (1-trillion square feet) of land. It's estimated that some 2-billion cups of coffee are consumed each day. It's thought that caffeine evolved in coffee to help protect the plant from predators, and it also helps with pollination. When the coffee leaves, where the highest level of caffeine is found, fall, it actually helps to poison the ground from other invasive plant species. In addition, once pollinators get a taste of the caffeine, they tend to "come back for more" which, as Victor Albert (a genome scientist at the university of Buffalo) stated, "is exactly what it does to us."
For the more technical information, Ewen Callaway from Nature.com reports, "When the team looked for gene families that distinguish coffee from other plants, those that make caffeine topped the list. The genes encode methyltransferase enzymes, which transform a xanthosine molecule into caffeine by adding methyl chemical groups in three steps. Tea and cacao, meanwhile, make caffeine using different methyltransferases from those the team identified in robusta. This suggests that the ability to make caffeine evolved at least twice, in the ancestor of coffee plants and in a common ancestor of tea and cacao."
Understanding the coffee genome could help scientists discover how coffee is able to combat different diseases and how it's able to more easily cope with climate change. Furthermore, if scientists understand how caffeine is produced in coffee, an added benefit is we'll be able to grow caffeine free plants, which would eliminate the chemical decaffination process we currently use - in the end, we'll have a much tastier cup of decaff.