1) With "to" -in order to express purpose
Here we are dealing with the clause of purpose(they explain why
something is done) which is introduced by "to". 'To" functions in your example as a conjunction and can be easily replaced with "in order to" or 'so as to".
Be careful, as 'to' can also be a part of full infinitive and you shouldn't use it after most of the modals.
Ex: I can/may/might/should/must help you.
2) without 'to'
Had better=should (is used to express advice ona specific situation) is followed by bare intinitive (without "to")
Note that in speech, people usually shorten had to ’d, and may not pronounce it at all.
Ex:I'd better not go out tonight; I'm really tired.