When is it best to write "can't" versus writing "cannot"? Are they interchangeable in every situation?
Grammatically, you can use can't instead of can not or cannot in the majority of circumstances. There is an exception. In wh-movement, the contraction should not be expanded unless you also change the word order:
Stylistically, the choice between can't and cannot is more complex. Generally, people use can't in speech and informal writing, and cannot or can not in formal writing or very formal speech. Also (as @Kris points out in a comment), cannot might be used when you need to carefully distinguish it from can't in speech.