Hi Jonas. It is really case, by case, but one difference is that you "do something for someone", while you "give or deliver something to someone". I think for is used more when something is being created for someone or something, while to is more about something being derived or traveling to somewhere.
I hope this was helpful. If you would like more examples and a more in-depth explanation, sign up for my tutoring lessons.
Sincerely,
Jacobo The Teacher