I have tried to use single sided buffers to make buffer on one side of of a line. But the buffer is sometimes changing sides as shown below:
What is the reason for this and how can I fix it?
Your line is made of several segments that have different orientations, so the "right" side of each segment is not always on the same side of the complete line.
To avoid this, you can first dissolve the line segments so that you are effectively buffing a single line. Alternatively, you can identify and swap direction of some segments.