Effect of ligand sensing on flagellar bundle formation in bacteria