I think that aggregate demand is not necessarily perfectly elastic. It could be - depending on the good - but that is not the point.
In perfect competition, each single firm faces a horizontal demand curve as competition is fierce and competitiors are offering the good at the same price. everyone is a price taker. if one firm increases their prices, buyers will simply go and buy from the other firms.
however, think about what would happen, if firms were to illegally set the price higher (collusion)? then, it would be like having only one firm. so, aggregate demand curves do not have to be horizontal even though every single company faces a horizontal curve.
that is how I understood it.