<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def tofile(path=""):
 """Instead of printing to a screen print to a file :Example: with pout.tofile("/path/to/file.txt"):
 # all pout calls in this with block will print to file.txt pout.v("a string") pout.b() pout.h() :param path: str, a path to the file you want to write to """

    if not path:
        path = os.path.join(os.getcwd(), "{}.txt".format(__name__))

    global stream
    orig_stream = stream

    try:
        stream = FileStream(path)
        yield stream

    finally:
        stream = orig_stream