1-Sometimes, when he is alone, he sings to himself.
2-Sometimes when he is alone he sings to himself.
3-From time to time, when he is alone, he sings to himself.
4-From time to time when he is alone he sings to himself.
In which case:
a-He sings to himself from time to time, that is, whenever he is alone.
and in which:
b-When he is alone, sometimes he sings to himself (and sometimes he doesn't)