To keep it from doing that, all you need is a rubber band. I have a handful of these as my boyfriend brings home a lot of it. I don't know where he gets it but I don't mind.
Now, all you need to do is put the rubber band around the ribbon this way and you'll never have a problem with a messy ribbon.
Some people would use a diaper pin or a pin and even put scotch tape at the end of the ribbon but I prefer it this way. Not only is it easy, it's also prick free for my fingers. Hope this helps.