All perfect praise be to Allah, the Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad, sallallahu ‘alayhi wa sallam, is His slave and Messenger.
What you did was correct according to the view of some scholars. The Maaliki scholar Muhammad ‘Ulaysh wrote, “It is not recommended for the praying person to interrupt the Fajr prayer in congregation to perform the Witr prayer if he remembers that he had not performed it. It is permissible for him, though, either to interrupt it or to finish it with the imaam. This was the view of Imaam Maalik – – and it is the most likely correct view in this regard.” [Minah Al-Jaleel]
Regarding your question, ''Is there anything else I could have done?” The answer is that you could have finished the Fajr prayer with the congregation and then made up for the Witr afterwards.
As for changing your intention from performing the obligatory prayer to the Witr, it invalidates the obligatory prayer and does not count as a valid intention for the Witr either. An-Nawawi wrote:
“Fourth: changing the intention from offering an obligatory prayer to offering a voluntary one is of two kinds: (first,) a change in ruling, such as the person who starts the Thuhr prayer, for example, by reciting Takbeerat Al-Ihraam before the due time of the Thuhr out of ignorance, it counts as a voluntary prayer. Second, if someone deliberately changes the intention from offering an obligatory prayer to offering a voluntary one during the prayer, the obligatory prayer is invalidated and the correct scholarly view in this regard is that such a prayer does not count as a voluntary prayer either.” [Al-Majmoo’]
Allah knows best.