Balancing the loss and acquisition of pathogenic traits in food-associated bacteria