In several places the Quran warns against dividing Islam into sects. But what does this mean? Is this a rejection of any type of categorization of Muslims? One can categorize Muslims by country, by sex, by age, and in many other ways. Is this a problem? I don't think so. So when is grouping Muslims a problem? I believe that it is a problem when the groups reject each other as Muslims. When group X says that group Y are not real Muslims, then group X is a sect. The issue isn't so much different groups as it is serious division within Islam.
How can this kind of division be avoided? A major source of division is differing beliefs. There are two ways that one can handle differing beliefs. One is to insist on one orthodoxy, one set of beliefs that everyone must hold. The other is to tolerate differing beliefs and allow different groups (schools of thought) to form with differing beliefs as long as they all accept each other as Muslims. The first approach was tried in Christianity and the results were a disaster. Enforcing uniform beliefs requires oppression and encourages making people stupid to prevent them from having their own ideas. This is what the Catholic Church did. Sunni Islam needs to be careful not to follow this path.
The best way to avoid sects is through tolerance. This means that Sunni, Shia, Sufi, Ahmadiyya, and Quranists should all be considered Muslim. You may disagree with the beliefs of some groups, but that doesn't mean that they aren't Muslim.
Is there a danger in having so much tolerance that complete hypocrites are accepted as Muslims? Yes, but this risk is still less of a danger than sectarianism. Defining a Muslim simply as one who says the shahada opens one up to this risk. A more conservative definition would be to define a Muslim as someone who follows the five pillars of Islam based on his own understanding. This at least requires some action by the person which means that he can't be a complete hypocrite, but it is still flexible enough to allow for differing beliefs.
I have a practical personal reason for raising this issue. I am a non-Muslim who follows the Old Testament and I am considering converting to Islam. For me, converting would not mean giving up the Old Testament, it would just mean accepting the Quran. I would follow both. I would call myself a Karaite Muslim which means that I would follow Islam (the Quran) based on my understanding which comes from the Old Testament. My interest in Islam comes from my understanding that there is no meaningful difference between the Old Testament and the Quran, and that in fact the Quran follows logically from the Old Testament. For me, the two fit perfectly together. Yes I admit that this is an unusual view, but it is my view. Whether I would be considered a Muslim or a heretic depends on the issues that I raised in this post.