I didn't notice you are using python 2. newline keyword was introduced in python3. if using python2 you need to open the faa file for writing in wb mode to avoid extra new lines on windows. what OS do you use? by the way it's better to work with python3, because official support for python2 will end soon.
with respect to dict it was small mistake, so don't worry
as to the algorithm - it's more matter of practice
here is updated code
annotations = {}
with open ('annotation.txt', 'r') as f:
for line in f:
data = (line.split())
annotations[data[0]] = line
with open('protein_file.txt', 'r') as f, open('proteinandannotation.faa', 'wb') as faa:
for line in f:
if line.startswith('>'):
line = line.strip()
protein_id = line[1:]
annotation = annotations.get(protein_id, '{}\n'.format(protein_id)) # if id is missing in annotations it will just return the id
faa.write('>{}'.format(annotation))
else:
faa.write(line)