The story of how King Dovid came to write the 15 “Shir HaMaalos” is recounted in Gemoro Sukkah 53 a, b .
It seems in preparing the “plumbing” for the future Temple, he disturbed an underground seal and the waters threatened to inundate the world. He then was taught that he could write HaShem's name on an earthenware shard and throw it into the waters. After this, the waters went down too far and he got them back to a reasonable level by composing and reciting the 15 “Shir HaMaalos”.
I would like to have a reference to (and a summary of) a source that teaches what we are expected to take from this story and what significance it has.