One has to see the full context regarding how the Mahavakya is spoken. The complete verse from Brihadaranyaka Upanishad is as:
ब्रह्म वा इदमग्र आसीत्, तदात्मानमेवावेत् ‘अहं ब्रह्मास्मि’ इति । तस्मात् तत् सर्वमभवतद्यो यो देवानां प्रत्यबुध्यत स एव तदभवत्तथर्षीणां तथा मनुष्याणां तद्धेतत्पश्यन्नृषिर्वामदेवः प्रतिपेदेऽहं मनुरभवं सूर्यश्चेति । तदिदमप्येतर्हि य एवं वेदाहं ब्रह्मास्मीति स इदं सर्वं भवति तस्य ह न देवाश्चनाभूत्या ईशते । आत्मा ह्योषां स भवत्यथ योऽन्यां देवतामुपास्तेऽन्योऽसावन्योऽहमस्मीति न स वेद तथा पशुरेवं स देवानाम् । यथा ह वै बहवः पशवो मनुष्यं भुञ्जयुरेवमेकैकः पुरुषो देवान्भुनक्त्येकस्मिन्नेव पशावादीयमानेऽप्रियं भवति किमु बहुषु तस्मादेषां तन्न प्रियं यदेतन्मनुष्या विद्युः ।
I-iv-10: This self was indeed Brahman in the beginning. It knew only Itself as, ‘I am Brahman’. Therefore It became all. And whoever among the gods knew It also became That; and the same with sages and men. The sage Vamadeva, while realising this (self) as That, knew, ‘I was Manu, and the sun’. And to this day whoever in like manner knows It as, ‘I am Brahman’, becomes all this (universe). Even the gods cannot prevail against him, for he becomes their self. While he who worships another god thinking, ‘He is one, and I am another’, does not know. He is like an animal to the gods. As many animals serve a man, so does each man serve the gods. Even if one animal is taken away, it causes anguish, what should one say of many animals ? Therefore it is not liked by them that men should know this.
Hope the above paragraph itself clears your confusion.
In the beginning, also Brahman is telling "I am Brahman" and now also it is telling "I am Brahman". In fact, Brahman doesn't change at all. There is only Vivarta Vada (apparent modification). So, the notion of individuality is itself perceived due to Avidya. So, the question of egoistic "Aham" doesn't rise at all.
"Aham Brahamasmi" in Advaita is called Anubhava Mahavakya ie.. this is to realize I am Brahman.