Flat, hard wafers of baked dough have basically existed for as long as people had flour, water and hot stones to bake it on. However, cookies as we know them - that is, sweet cookies - first appeared in the middle east in the 7th century, as that is where sugar was first refined. Sugar, and confections made with sugar, then spread west throughout Europe through trade routes etc.
The earliest recipes *I* could find (and read, Middle Persian is not a language I'm familiar with :P) and recognize as "cookies" in the modern sense were English ones from around the turn of the 17th century. Cookies at this time were often called, rather confusingly, "cakes". Sometimes they were called "jambals" or "jumbles" which may have been a transliteration of an earlier Persian word. Interestingly (at least to me) the word "jumble" for cookie came into use before the word "jumble" was used to mean "a mixture of stuff" so it could be that the word originally came from cookies!
The modern American word "cookie" comes from the Dutch "koekje" meaning a little cake, while "biscuit", the word used by most of the rest of the English speaking word, comes from the Latin "bis coquere" meaning "twice cooked". Many early cookies were cooked in a two stage process which included baking gently and then drying in an oven, or boiling and then baking.
Ok, that's enough history and etymology for now. ;) Time for some cookies!