Call $S$ the set of periodic functions from $\mathbb{R}$ to $\mathbb{R}$. We will show that $S$ is not a vector space. During the proof, I will try to explain the motivation behind every step taken. If you are in a hurry, just go to the item (3c).
In the attempt in the question, it was assumed that $f$ and $g$ have the same period $p$, which is not always the case.
As the author of the question pointed out, to check whether a set $S$ is a vector space, we must check three things: (1) $S$ it's not empty, (2) $S$ it's closed under addition and (3) $S$ is closed under scalar multiplication. Let's check these properties one by one.
(1) $S$ is not empty
Well, take the constant function $f(x) = 5$. Then $f(x+42) = f(x)$ for every $x \in \mathbb{R}$, which means $42$ is a period of $f$. Of course I could take another number to be a period --- $42$ just happens to be one I like. Could be $11$ or $13$, if you prefer. We checked that $S$ is not empty.
(2) $S$ is closed under multiplication by a scalar
If $f$ is periodic with period $p \in \mathbb{R}$, then by definition $f(x+p) = f(x)$ for every $x \in \mathbb{R}$. Then the function $\lambda f$ is also periodic, because $(\lambda f)(x+p) = \lambda \cdot f(x+p) = \lambda \cdot f(x) = (\lambda f)(x)$.
(3) $S$ is closed under addition
Let's try to prove $S$ is closed under addition. It won't work, because it's not! Take $f_1$ with period $p_1$ and $f_2$ with period $p_2$. We must show that $g = f_1 + f_2$ is also periodic.
(a) Sometimes $g = f_1 + f_2$ is in fact periodic. Take a look. Suppose $f_1$ has period $p_1 = 5$ and $f_2$ has period $p_2 = 7$. Then $f_1$ repeats itself on intervals of length $5$ and $f_2$ repeats itself on intervals of length $7$. Well, on intervals of length $5 \cdot 7 = 35$ both $f_1$ and $f_2$ repeats themselves. To be more precise, $(f_1+f_2)(x+35) = f_1(x+35) + f_2(x+35) = f_1(x + \mathbf{5} \cdot 7) + f_2(x + \mathbf{7} \cdot 5) = f_1(x) + f_2(x) = (f_1+f_2)(x)$.
(b) It appears that we can generalize that, but we can't. Take $f_1$ with period $p_1$ and $f_2$ with period $p_2$. Then $f_1$ repeats itself on every interval of length $p_1$, which means $f_1$ repeats itself on every interval of length $p_1 \cdot p_2$, right? Wrong! There is a problem: if $p_1 \cdot p_2$ is irrational, we cannot say that --- $f_1$ repeats on every interval of length $p_1$, so it repeats on every interval of a multiple of $p_1$. But a multiple of $p_1$ is $p_1$ times an integer value.
(c, a counterexample) Finally, let's look for a (very simple) counterexample. It get's ugly if look for your everyday functions like $sin(x)$ and $cos(x)$. Look for simpler (although artificial ones).
Take $f_1(x) = 1$ in the interval $[0,1/2]$, $f_1(x) = 1000$ in the interval $(1/2,1]$ and $f_1(x+1) = f_1(x)$. So $f_1$ has fundamental period $p_1 = 1$. Actually, the graph of $f_1$ is just two horizontal lines, $y=1$ and $y=1000$, repeating themselves.
Take $f_2(x) = 3$ in the interval $[0,1]$, $f_2(x) = 3000$ in the interval $(1,\sqrt{2}]$ and $f_2(x+\sqrt{2}) = f(x)$. So $f_2$ has fundamental period $p_2 = \sqrt{2}$. Actually, the graph of $f_2$ is just two horizontal lines, $y=3$ and $y=3000$, repeating themselves.
Suppose $g = f_1+f_2$ is periodic. Then there is a $P \in \mathbb{R}$ such that $(f_1+f_2)(x+P) = (f_1+f_2)(x)$ for every $x \in \mathbb{R}$. That means $f_1(x+P)+f_2(x+P) = f_1(x)+f_2(x)$ for every $x \in \mathbb{R}$. Due to the way $f_1$ and $f_2$ behave, that means $f_1(x+P) = f_1(x)$ and $f_2(x+P) = f_2(x)$ for every $x \in \mathbb{R}$.
Because $p_1 = 2$ is the fundamental period of $f_1$, that means $P$ is a multiple of $p_1$. In other words, $P = k_1 p_1$ for some $k_1 \in \mathbb{N}$.
Because $p_2 = \sqrt{2}$ is the fundamental period of $f_2$, that means $P$ is a multiple of $p_2$. In other words, $P = k_2 p_2$ for some $k_2 \in \mathbb{N}$.
Well, that means $p_2 / p_1 = k_1 / k_2$, with $k_1, k_2 \in \mathbb{N}$. But $p_2 / p_1 = \sqrt{2}$. It implies that $\sqrt{2}$ is rational. So our hypothesis, that $f_1+f_2$ is periodic, is false. Therefore $f_1+f_2$ is not periodic and $S$, the set of all periodic funtions, is not a vector space.