Ensure that last line of output file is always newline terminated

Have noticed that the scripts that result from use of sem-add have the last line without a newline. This seems to be happening due to use of strip which strips the string (that stores the contents of input file) of all trailing newlines and when "out << contents" is done the output file has the last line without newline termination.