As stated it is not clear how Rabbi Dosa could have said the Halacha of Maaser Ani in Amon & Moav in the Shemita year to refute a saying of Rabbi Elazar Ben Azarya - after all he did not know that Rabbi Elazar Ben Azarya had been born, as shown by his remark "Oh' so our friend Azarya has a son". Of course this need not be taken literally: it may be taken to mean that Rabbi dosa did not know that the son of his friend Azarya was an important talmid Hacham, who would be coming to visit him with Rabbi Yehoshua! Nevertheless it indicates that Rabbi Dosa had not heard any Halachot in the name of Rabbi Elazar ben Azarya - so he could not have quoted a Halacha to counter one of Rabbi Elazar Ben Azarya!!
I would suggest that the Halacha of Rabbi Elazar Ben Azarya - that the applicaple Maaser is Maaser Sheni - did not originate with Rabbi Elazar Ben Azarya, but was the opinion of Azarya, his father.
Rabbi Dosa knew this, and therefore stated the tradition of Haggai - JUST IN CASE that Rabbi Elazar Ben Azarya had received the Halacha from his father.
Indeed his guess was correct, and Rabbi Elazar Ben Azarya needed this input from Rabbi Dosa!
Rebbi Dosa was certainly familiar with this opinion, as it was a tradition that had been handed down for many generations (Chagigah 3b). As far as how he knew that Rebbi Elazar ben Azaryah held like this opinion, we wrote in the Insights that perhaps Rebbi Elazar ben Azaryah had expressed his opinion when discussing various Halachos with Rebbi Dosa earlier in their conversation.