Build a variable and only write to file once