The urge to scratch the floor or ground before lying down may be residual instinct from a dog's ancestors. Scratching helped remove sticks and stones, even out the ground and make it into a hole for sleeping.
Many dogs demonstrate the same circling and scratching the ground behaviors before lying down to sleep. Even if this habit does not appear to accomplish anything, especially on a hardwood floor or carpet, it may have roots in instinct. Circling and scratching the ground helped to prepare it to be slept in that night.
Scratching the ground removed hard sticks and stones from the sleeping area. It also helped to loosen the soil and make it less hard. Sometimes, dogs dig enough to create a hole to sleep in. The hole exposed cooler dirt under the surface during a hot summer, and created a bit of shelter to preserve body heat in the winter.
The act of circling and scratching may also help scare off any critters hiding in high grasses, such as snakes and insects. A wolf might even be able to catch and kill something potentially dangerous that was hiding in that spot. Domesticated dogs still have this urge ingrained in their DNA, even if it does not serve a purpose inside the home.