Several transforms of the same element

I need to perform several transforms of the same element. I tried the following:

import org.apache.beam.sdk.Pipeline;
import org.apache.beam.sdk.coders.StringUtf8Coder;
import org.apache.beam.sdk.io.TextIO;
import org.apache.beam.sdk.options.PipelineOptions;
import org.apache.beam.sdk.options.PipelineOptionsFactory;
import org.apache.beam.sdk.transforms.*;
import org.apache.beam.sdk.values.PCollection;
import org.apache.beam.sdk.values.PCollectionList;

import java.util.Arrays;
import java.util.List;

public class TestPipeline {
  public static class TransformWords extends PTransform<PCollection<String>, PCollection<String>> {
    @Override
    public PCollection<String> expand(PCollection<String> lines) {
      PCollection<String> uppers = lines.apply(ParDo.of(new DoFn<String, String>() {
        @ProcessElement
        public void processElement(ProcessContext c) {
          String line = c.element();
          c.output(line.toUpperCase());
        }
      }));
      PCollection<String> lowers = lines.apply(ParDo.of(new DoFn<String, String>() {
        @ProcessElement
        public void processElement(ProcessContext c) {
          String line = c.element();
          c.output(line.toLowerCase());
        }
      }));
      PCollectionList<String> collections = PCollectionList.of(lines).and(uppers).and(lowers);

      PCollection<String> merged = collections.apply(Flatten.<String>pCollections());
      return merged;
    }
  }
  public static void main(String[] args) {
    final List<String> LINES = Arrays.asList(
      "fOo",
      "BaR",
      "bAz",
      "QuUiX"
    );

    PipelineOptions options = PipelineOptionsFactory.create();
    Pipeline pipeline = Pipeline.create(options);

    pipeline.apply(Create.of(LINES)).setCoder(StringUtf8Coder.of())
      .apply(new TransformWords())
      .apply(TextIO.write().to("./output.txt"));

    pipeline.run().waitUntilFinish();
  }
}

But it waits for all the transforms to finish before it starts writing results.

After that, I reimplemented the composite transform as public static class TransformWords extends PTransform<PCollection<String>, PDone>. So I applied a transform and after that saved the results with TextIO.Write. But it resulted in duplicate code and also I had to pass output prefix to composite transform’s constructor.

Are there any ways to run several transforms on the same element without such timing issues and/or duplicate code, complexity and unnecessary redundancy?