The difference is probably here (this is exactly how I also first implemented the TM algorithm). In the official algorithm, there are a couple of differences:
Only grow connections to previously active winner cells (not to ones which were not winners)
If a segment has “max new synapse count” active synapses when its post-synaptic cell becomes predicted active, then do not grow any additional synapses (to winners or otherwise)