Repository: PrefectHQ/prefect

Issue:
flow.visualize() writes two files when `filename` is given
## Description

Today I attempted to write the output of `flow.visualize()` to a file. I found that when you provide `filename` to `flow.visualize()`, two files are written.

## Expected Behavior
*What did you expect to happen instead?*

Given this code

```python
flow.visualize(filename="c00l-flow", format="png")
```

* **what I expected:** one file called `c00l-flow.png` is created, with the viz content
* **what happened** an empty file `c00l-flow` is created AND a `c00l-flow.png` is created with the viz content

![image](https://user-images.githubusercontent.com/7608904/83915173-57b97300-a738-11ea-910a-ed9e2b38d6e9.png)

## Reproduction
*A minimal example that exhibits the behavior.*

```python
from prefect import task, Parameter, Task, Flow

@task
def task1():
    return 1

@task
def task2(n: int):
    return n + 1

with Flow('test-flow') as flow:
    x = task1()
    y = task2(x)

# produces two files
#   - c00l-flow.png (empty)
#   - c00l-flow.png.pdf (vizcontent)
flow.visualize(filename="c00l-flow.png")

# produces two files
#   - c00l-flow.png (empty)
#   - c00l-flow.png.png (viz content)
flow.visualize(filename="c00l-flow.png", format="png")
```

## Environment
*Any additional information about your environment*

<details><summary>conda info</summary>

```
     active environment : None
       user config file : /home/jlamb/.condarc
 populated config files : 
          conda version : 4.8.3
    conda-build version : not installed
         python version : 3.7.6.final.0
       virtual packages : __glibc=2.27
       base environment : /home/jlamb/miniconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/jlamb/miniconda3/pkgs
                          /home/jlamb/.conda/pkgs
       envs directories : /home/jlamb/miniconda3/envs
                          /home/jlamb/.conda/envs
               platform : linux-64
             user-agent : conda/4.8.3 requests/2.23.0 CPython/3.7.6 Linux/5.3.0-7625-generic ubuntu/18.04.4 glibc/2.27
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False
```
</details>

Using `prefect` 0.11.5, installed from PyPi with `pip`.

I thought this might be related to #2500, but when I rolled back to `prefect` 0.11.4 I got the same behavior.




Discussion:

Resolving patch:
diff --git a/src/prefect/core/flow.py b/src/prefect/core/flow.py
--- a/src/prefect/core/flow.py
+++ b/src/prefect/core/flow.py
@@ -1243,7 +1243,7 @@ def get_color(task: Task, map_index: int = None) -> str:
                 )
 
         if filename:
-            graph.render(filename, view=False, format=format)
+            graph.render(filename, view=False, format=format, cleanup=True)
         else:
             try:
                 from IPython import get_ipython


Test patch:
diff --git a/tests/core/test_flow.py b/tests/core/test_flow.py
--- a/tests/core/test_flow.py
+++ b/tests/core/test_flow.py
@@ -1211,12 +1211,9 @@ def test_viz_saves_graph_object_if_filename(self):
 
         with tempfile.TemporaryDirectory() as tmpdir:
             with open(os.path.join(tmpdir, "viz"), "wb") as tmp:
-                graph = f.visualize(filename=tmp.name)
-            with open(tmp.name, "r") as f:
-                contents = f.read()
-
-        assert "label=a_nice_task" in contents
-        assert "shape=ellipse" in contents
+                graph = f.visualize(filename=tmp.name, format="png")
+            assert os.path.exists(f"{tmp.name}.png")
+            assert not os.path.exists(tmp.name)
 
     def test_viz_reflects_mapping(self):
         ipython = MagicMock(