The phrases below can all mean "I don't know which course of action I should take":
I don't know what I should do.
This one emphasizes that you're trying to pick the 'correct' action. The one that you should do. You may not actually take this course of action, but people usually try to do what they think they should do, so you probably will.
I don't know what to do.
I'm not sure why, but I feel like this phrasing implies greater uncertainty. I might be more likely to use this if I'm not even sure what my options are.
I don't know what I will do.
I would consider this the standard phrasing, without any additional connotations. I would be more likely to use a contraction in the sentence, so:
I don't know what I'll do.
In response to the question title, rather than the question body, the 'to' is just there as part of the infinitive form of the verb 'to do'.
Without the 'to', you would have
I don't know what do.
Which is both ungrammatical and ambiguous. You don't know what what does? What cars do? What women do? What gerbils do?
Adding in the 'to' makes the abstract 'to do' which is referring to potential actions to be taken by the speaker.
More technically, 'to do' in this sentence is a hollow non-finite clause. Which, as that article points out, has an implied object from earlier in the sentence or greater context. In this case, the implied object of 'to do', i.e. the thing that is being done, is 'what'. Here, 'what' is a pronoun standing in for the possible courses of action.