I've changed it to mkstemp() as it's more convenient in this case.