The photo together with the description of their behavior shows that you have an infestation of pantry moths. What you found are the larvae at their last stage before pupating, they tend to wander around a bit before doing so. Before, the larvae were munching on food somewhere in your home, leaving their feces and often webbing behind.
An infestation of pantry moths means you need to check all your food that may be a food source for them - and they enjoy a surprisingly diverse diet. Main food sources are grain-based products, legumes, dried fruit, nuts and other seeds, but the will also munch on pet food, chocolate, spices... The general rule is that everything in cartons or plastic bags needs to be either discarded or be treated (frozen for a few days or microwaved). This may sound excessive, but if only a few eggs remain, the cycle starts anew. Don’t forget potential moth hideouts outside the kitchen, the larvae wander rather long distances and the adults fly. Clean out the cupboards, vacuum them (especially all cracks and corners), wipe them out. If possible, store your susceptible staples in sealed jars, this will prevent wandering female moths from laying eggs and keep hitchhikers from stores confined in one jar, preventing a larger infestation in the future.