you can write wherever you can write....and some folks can write very well in coffee shops.
That said, if I had to wager I would bet a very large majority of those writing in coffee shops either do so because they are convinced that's what being a writer IS (they probably also make sure to be angsty and purple in their writing, and dress however they assume a writer does...hipster, perhaps) or because they are trying to make very certain others are around to actually see them writing. Again, not to slam the folks who do write well in them, only a suspicion that a lot of the folks working there are less worried about the work than being seen.
Clearly neither of the two options above is in your best interest, so if you write well in public, do so, but if you don't, well, there are lots of places to write besides coffee shops. Personally, I gawk too much.