Let me give you one religious perspective, and probably a minority religious perspective at that.
What’s needed to make the best decision—is a knowledge of the future, and none of us have that. You could give the money to charity, but as it turns out, the person was carrying the box under false pretenses and uses the money to buy a weapon which he ultimately uses to kill someone. Or it’s a genuine charity, but they don’t use the funds wisely, or it is what you might ideally think it is.
Not only do you need to know the future, you also have to know about the essence of all things—again, knowledge beyond our ken.
Buying the cake could very well lead to a feeling of kindness in those at the family gathering, which could lead to charity given at another venue, or cause a discussion which sparks an idea that ultimately leads to the cure for a disease. We cannot know the full spectrum of what can possibly happen.
At some point, to function ethically, if you want to, a person has to know their own heart, and trust it—a monumental task, that might be the ultimate spiritual/religious challenge. Another way to phrase this notion of knowing your heart is ‘expanding your consciousness’.
I think that the whole notion that reality can be broken down into a base 2 series of choices creates a false representation of reality, in which case, believing in this base 2 notion stops a person from connecting to their heart, contracts their consciousness, which renders both choices somewhat flawed.
Now, a lot of religions and religious people have accepted this reduction of reality—which keeps questions like this going. They’ve even played a part in generating this illusion.
If you break out of this base 2 notion of reality, you will encounter the idea of ‘intention’. But that’s another issue. First, break out of the illusion.