insertSegmentsToFile method