Write file in stream and return