This is probably due to some food infection you got. May be it could be due to nail eating because of the dirt which went into the stomach with nails.
Irregular stool and bloating can also be due to stress which could be due to many causes from your day to day life
Next Steps
Nail eating habits can be modified by simple motivation tricks like treat yourself when you dont eat do it for a day then for a month and slowly. Stress induced irregular bowel habits can be modified by increasing some physical activities in your daily routine