ついでに doesn't connect well to 感じ but directly to なっている.
If you are asking about the difference between the original sentence and this one, this sentence would mean the speaker feels buying sweets has actually become a secondary purpose with the primary purpose being buying something for him.
I have a feeling that it (= buying sweets) has become secondary to buying something for him
ような感じ in the original sentence is understood as referring to an impression an outside observer would get from what he's doing.
I have a feeling that it (= the current situation) has taken on an appearance as if it (= buying sweets) has become secondary to buying something for him
The original sentence, including the part where it says 気のせい, sounds like the speaker is trying to convince himself that buying something for him is not the main reason for being there although it might look like it.