It's fairly easy to understand why authors would attribute works to someone other than themselves. Mainly, by attributing the work to a well known individual, be it Moshe or Avraham or whoever, then it becomes more likely that the work will receive attention. We see this happen all the time with religious writings. The entire book of Mormon is attributed to mythical individuals. The Zohar, "discovered" in the Middle Ages, is attributed to Moshe. In fact, there are tons of works from 200-400 CE that were attributed to other individuals. You can see a list here. Most of these were rejected from the Biblical canon but some made it in.
Kohelet Claimed Authorship
Kohelet (Ecclesiastes) doesn't have an explicity claim of the author. However, two sentences in the first paragraph are used to give the usual attribution to Shlomo (Solomon) (Eccl 1:1,12)
1 The words of Koheleth, the son of David, king in Jerusalem....,12 I Koheleth have been king over Israel in JerusalemNow, it is entirely possible to interpret "son of David" as descendent of David and therefore Kohelet could have been written by a later individual. Indeed this is the opinion of the Gemara in Bava Batra 15b which attributes the book to the time Hizkiyahu (Hezekiah). Of course both of these are impossible and we'll see why now.
The reason Kohelet cannot be written at the time of Shlomo is that it includes words that would not have been known to anyone at the time. The words are Pardes (cognate with English Paradise) which literally means garden and appears in 2:5 and Pitgam which means decree and appears in 8:11. Pitgam also appears several times in the book of Esther, set in Persia.
Jews living in Israel had absolutely no contact with Persia until the Babylonian exile. They knew of the empire to the east of the Assyrians and Babylonians, which was the Median empire until the conquest of Cyrus in 550 BCE. However, there is no strong influence of Persian culture until the conquest of Babylon and the next few centuries when the Persians controlled Israel. It's during this period that we start seeing the strong influence of Persian culture on Judaism.
For Hizkiyahu or Shlomo to have used Pardes or Pitgam would be akin to a Jew during the Persian period using the word Sanhedrin or Afikomen which are derived from Greek, or like a Jew in the 1st century using the word Shvitz or Schlepp. In other words, the loanwords provide markers for the earliest possible date of the work, and in this case we can very confidently date Kohelet to the Exilic period at earliest.