Each word in a sentence has a "function," a way it is being "used." So words are subjects or modifiers or connecting words. It is from this "function" that we determine the part of speech.
One of the least understood functions is something called an adverbial objective. An adverbial objective is a noun that is being used to answer one of the adverb questions: when, where, why, how. This word with its adjective modifier denotes a distance or measurement or quantity or amount.
...I wasted two hours with him. (How much time did I waste?)
...We were there three weeks. (How long were we there?)
...It weighed ten pounds. (How much did it weigh?)
And this, then, allows for a while to be two words -- a noun indicating how much time.
...We were there a while. (How long were you there?)
So the word a while can ALWAYS be two words.
Happy punctuating!
Margie