They're slightly different grammatically.
In the first, "a while" is adverbial. You will sometimes see this written as one word, especially in AmE contexts.
In the second, "a while" is a noun phrase. It means "a short time". It has to be two separate words here.
There's no difference in meaning.