"Only + full infinitive" is a set construction. It points to a surprising or frustrating subsequent event. Sometimes it can be replaced by the weaker "but + finite verb".
I went into town to buy a new suit, only to find that I'd left my wallet at home. I went into town to buy a new suit, but found I'd left my wallet at home.
Songs that contains the expression