The demand curves for firms in perfect competition are perfectly elastic because the firms in perfect competition are selling homogeneous goods. Homogeneous goods are all perfect substitutes for one another, causing demand for those goods to be perfectly elastic.
One cause of elastic demand is the presence of substitutes for a good. If you are selling a good for which there are few substitutes, you can probably get away with raising its price because people will not have many options of other goods to buy. If, by contrast, there are many substitutes for your good, demand for it will be very elastic. If your raise your price, consumers will simply buy from someone else.
In perfect competition, there are essentially infinite substitutes for your good. Your good is homogeneous and many other sellers are selling exactly the same thing. If you raise your price, consumers will simply buy from someone else. Therefore, demand will be perfectly elastic.