I am aware that some Japanese words can be written in either kana or kanji and that the rules about it are not set in stone. This has already been discussed in some questions and answers here (e.g. Usage of kanji for words usually written in kana) but my question is more specific.
My question is about why sometimes the same word would appear once written in kanji and once written in kana very close to each other. For example, in Haruki Murakami's story I'm reading now (「かえるくん、東京を救う」), there's two different way of spelling of 何/なに and 僕/ぼく within the same short paragraph. This is a continuous utterance by the same one character in the story.
Why is it spelled differently like that? Does it have any meaning? Is it just style? The sentences with 「考えている」 are very similar to each other, yet 何/なに is spelled differently.
The same difference in spelling is not limited to those words or this paragraph. It happens throughout the story and affects different words.
I feel that the answers below, while helpful, didn't really provide the ultimate answer to my question (or maybe such an answer just doesn't exist). I especially feel that concentrating on ぼく written with kana to mean childish language is not on the mark as the context of the story doesn't suggest that (I don't blame the helpful people who answered the question for that - they don't know this context).
I can also add an example from another story 「蜂蜜パイ」 from the same collection of short stories. Again two different ways of spelling are in the same passage, close to each other, spoken by the narrator this time.