A pervert who groped a young girl as she made her way home from school has been spared a jail sentence.