According to many dictionaries, hartnäckig means something along the lines of persistent, but I don't know exactly when I should use it. Does it have a bad connotation (like "stubborn")? Is it more common in everyday speech or in written language?
Hartnäckig does not have a pejorative meaning by itself, but it is most commonly used in a context with a negative statement.
The first example on Wiktionary conveys a disapproving sense:
Unser Lehrer bleibt immer so hartnäckig bei seiner Meinung.
Loosely translated, "Our teacher always remains adamant about his own opinion".
You could replace it with stur (stubborn) here, which gives even more emphasis on the negativity of the statement.
So, when you refer to insisting on one's opinion in an obstinate manner, hartnäckig certainly conveys a negative sense.
So, another example: a persistent cough, in German hartnäckiger Husten, is obviously very annoying and the word hartnäckig has a tendency towards negativity. Again, it's basically about the context. Even without the word hartnäckig, the cough is quite an aggravating thing, but the fact that is maintains makes it really nasty.
So, now an example with a positive sense, taken from from zeit.de.
Sie arbeiten hartnäckig am Erfolg, geben nicht auf und meistern so die schwierigsten Aufgaben.
A rough translation, "They work determinedly for their success, they never give up and, therefore, overcome they most difficult tasks".
It's quite obvious that working hard is a good thing. And when you maintain this hard-working manner even when you face some headwinds, this is a good. So, hartnäckig has a positive meaning here.
I think that this word is quite equally common in spoken language as well as written texts. It's hard to prove this, though.
According to the Wortschatz-Portal, typical collocations are Gerüchte, Vorurteile, Irrtümer, Klischees, Mythen and the verbs leugnen, weigern and (fest)halten. This is what makes the word seem disapproving, because it's often used in a negative context.