Your sentence is very well constructed.
'To have bought' is called a perfect infinitive and it is used to refer to something that happened previous to the time reference of the previous verb, which in your example is 'was'. First I bought, then I was lucky.
The reason we use an infintive here is the use of the adjective 'lucky'. Verbs which follow adjectives are usually in the infinitive form. 'I am happy to be here.' By using a perfect infinitive we change the time reference of the infintive.
You can often replace the perfect infinitive with a clause. 'I was lucky that I bought the very last tickets'.
'Very last' means 'last remaining or final', so it works really well here to emphasize that after you bought yours there were no more tickets available.