smcder
Paranormal Adept
In your example above, I would say that pain serves as an identifying phenomenon that provides motivation for an organism to avoid damage. It may be the case that it is not strictly necessary because some other non-phenomenal system could handle the task, and I would suggest that in some living things, particularly much more basic systems, that is exactly what is going on.
However nature has obviously found that pain is useful in our avoidance of biological damage, and therefore it is something we have evolved with, because that's how evolution works. It may also be the case that pain is a shortcut for what would otherwise be more complicated non-qualia based biological control systems in species that are more complex. It also facilitates the choice of whether or not we want to ignore it despite the unpleasantness.
This is what I wanted to quote in the post about deer antlers. Can you guess what the purpose is (without looking it up?)