The two points that clairewait has mentioned are vital to harmony in being roommates. College students, in their own journal writing, have underscored these points repeatedly, and from personal experience, this is the truth!
If the person who is a lark, gets up and leaves the room or apartment, things are all right; likewise, if the night owl, just stays out somewhere else and is quiet about returning and retiring, there can be no problem. But, even then, it is difficult not to disturb someone.
Another point that is important for females, especially: Do not room with someone who wears the same size. That favorite outfit or those favorite shoes may be ruined or gone when you want them.
Certainly, mutual respect and consideration for others is the best assuredness of harmony with a roommate. If two people are from the same socio-economic class they often have similar values, which helps. Surprisingly, only children sometimes make better roommates than others if they are eager to have a sibling type of relationship. At any rate, learning to think about others is good preparation for marriage, indeed.
I think that it might bear some importance when starting off living on one's own. I think that there are so many challenges in undertaking this aspect of living one's life that it makes things easier to live with someone that has similarities to you. If we think of those first stages where one is living outside of their home, there are so many elements that are challenges. To be able to enter a domain of the private where some sanctuary can be experienced with someone of similar values could be really important in this light. One is making the assumption that there is a relative feeling of "getting along" with the roommate, and this helps to make things much easier. When experience has been garnered, then I am not sure it matters as much, but in those early and formative stages from when one leaves home, I think it's essential to be able to have a roommate who is similar in a sense to you.
Based on my experience from college, there are two highly important things to figure out before moving in with someone (especially if you are going to share a room).
#1: sleep schedules - if you are a night owl and your roommate is a morning person, the schedule conflict will keep both of you up.
#2: cleanliness - if you are a neat freak and your roommate is not, you will eventually come resent each other.
I actually think it is a better idea not to be best friends with your roommate (this would be different if we were talking about a spouse). You will spend so much time with this person at home, that if you are also completely connected away from home, it is almost like you cannot get a break from each other.
Outside of marriage, I don't think it is that important.
When I was in high school (boarding school) and college, I lived with lots of people who were very different than me. As long as we kept basic levels of respect for one another it did not matter if we liked the same music or could tolerate the same amount of messiness or whatever.
In a marriage, I think it is more important to share similarities, but only on important stuff. My wife and I have very different tastes in hobbies and (to some extent) books and music. But we are in agreement on money matters and how we raise our kids. Those are the biggest areas that can end up causing serious trouble in a marriage and so I think those are the areas where you have to be similar.